<template>
  <div>
    全选: <input type="checkbox" />
    <div v-for="item in data" :key="item.id">
      <input type="checkbox" /> 商品:{{ item.name }} 库存:{{ item.num }} 价格:{{
        item.price
      }}
      <button @click="$emit('addtocar', item), add(item)">添加进购物车</button>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
let data = ref([
  {
    id: 1,
    name: "雪山飘雪",
    num: 67,
    price: 32,
  },
  {
    id: 2,
    name: "雪山飘1",
    num: 67,
    price: 82,
  },
  {
    id: 3,
    name: "雪山飘2",
    num: 667,
    price: 1222,
  },
  {
    id: 4,
    name: "雪山飘3",
    num: 88,
    price: 39,
  },
]);
let add = (ele) => {
  data.value.find((item) => {
    return item == ele;
  }).num--;
};
</script>

<style></style>
